#ifndef EM80_FWVERSION_ENQUIRY_HPP
#define EM80_FWVERSION_ENQUIRY_HPP

#include "../packet_base.hpp"
#include "../payload_headers.hpp"
#include "../../v8stdint.h"

#include <memory>

namespace em80_driver
{

class FWVersionEnquiry : public EM80PayloadBase
{
public:
    FWVersionEnquiry(EM80PacketPtr &packet) : EM80PayloadBase(packet, "FWVersionEnquiry", false, 1) {}

    struct Data
    {
        Data() : null(0) {}
        uint8_t null;
    };

    Data data;

    ~FWVersionEnquiry() {}

    //not to be used directly by external source
    bool serialize()
    {
        //TODO : is it directly control the raw data
        std::shared_ptr<Buffer> byteStream = std::make_shared<Buffer>(0);
        buildBytes(static_cast<uint8_t>(Header::FWVersionEnquiry), *byteStream);
        buildBytes(static_cast<uint8_t>(length), *byteStream);
        buildBytes(data.null, *byteStream);
    
        int i = 0;

        for(auto iter = packet->payload(); iter != packet->payload() + length + 2; iter++, i++)
        {
            *iter = (*byteStream)[i];
        }

        return true;
    }

    bool deserialize()
    {
        std::vector<uint8_t> byteStream;

        byteStream.assign(packet->payload(), packet->payload() + static_cast<uint32_t>(length) + 2);


        //TODO: check them
        uint8_t header_id, length_packed;
        buildVariable(header_id, byteStream);
        buildVariable(length_packed, byteStream);
        buildVariable(data.null, byteStream);

        return true;
    }
};

} // namespace em80_driver

#endif /* EM80_FWVERSION_ENQUIRY_HPP */
